package com.xinggq.pay.service.service.impl;

import cn.hutool.core.lang.Validator;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinggq.pay.service.context.AppIdContext;
import com.xinggq.pay.service.dto.ChannelInteractionRecordDTO;
import com.xinggq.pay.service.entity.ChannelInteractionRecordEntity;
import com.xinggq.pay.service.mapper.ChannelInteractionRecordMapper;
import com.xinggq.pay.service.service.ChannelInteractionRecordService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Service;


/**
 * 支付渠道接口交互记录 服务实现类
 *
 * @author system
 * @since 2024-01-01
 */
@Service
@Slf4j
public class ChannelInteractionRecordServiceImpl extends
    ServiceImpl<ChannelInteractionRecordMapper, ChannelInteractionRecordEntity> implements
    ChannelInteractionRecordService {

  @Resource
  private ChannelInteractionRecordMapper channelInteractionRecordMapper;

  /**
   * 保存请求记录
   */
  @Override
  public boolean saveRequestRecord(ChannelInteractionRecordDTO requestRecordDTO) {
    Validator.validateNotNull(requestRecordDTO, "请求记录DTO参数不能为空");

    ChannelInteractionRecordEntity record = new ChannelInteractionRecordEntity()
        .setTradeNo(requestRecordDTO.getTradeNo())
        .setPayChannel(requestRecordDTO.getPayChannel())
        .setChannelTradeNo(requestRecordDTO.getChannelTradeNo())
        .setRequest(requestRecordDTO.getRequest())
        .setResponse(requestRecordDTO.getResponse())
        .setAppId(AppIdContext.getAppId());

    return this.save(record);
  }

}